package com.example.administrator.kotlindemo

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import android.widget.Toast

class MainActivity : AppCompatActivity() {
    //kotlin基本数据类型
    //int
    val a: Int = 10000
    //字符串
    var str = "234234"
    //double
    var bDouble: Double = 3.1414
    var b: Int = 4000
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var text = findViewById<TextView>(R.id.text_kotlin_test2) as TextView
        text.setOnClickListener(View.OnClickListener {
            startActivity(Intent(this, SecondActivity::class.java))

        })
        Log.e(a.toString(), "33333333333333333333333");
        if (a > b) {
            Toast.makeText(this, a.toString(), Toast.LENGTH_LONG).show()
        } else {
            Toast.makeText(this, b.toString(), Toast.LENGTH_LONG).show()
        }

        if (!ChineseNameTest(text.text.toString())) {
            Toast.makeText(this, "不正确", Toast.LENGTH_LONG).show()
        } else {
            Toast.makeText(this, "正确", Toast.LENGTH_LONG).show()
        }

    }

    fun ChineseNameTest(name: String): Boolean {
        if (!name.matches("[\u4e00-\u9fa5]{2,4}".toRegex())) {
            println("只能输入2到4个汉字")
            return false
        } else
            return true
    }

}
